<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
</head>
<body>
<!--<script-->
        <!--src="https://code.jquery.com/jquery-3.3.1.min.js"-->
        <!--integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="-->
        <!--crossorigin="anonymous">-->
<!--</script>-->
<script language="JavaScript" src="js/jquery-3.4.1.js"></script>

    <form action="#" id="registForm">
        <div id="debug"></div>
        邮箱<input type="text"  id="email"> <input type="button" value="发送验证码" id="sendCodeBtn"> <br/>
        密码<input type="password" id="password"><br/>
        确认密码<input type="password" id="password2"><br/>
        验证码<input type="text" id="code">
        <input type="button" value="注册" id="registBtn"><br/>
        <a href="login.html">已注册，直接登录</a>
    </form>

<script>
    $(document).ready(function(){
        $("#email").blur(function(){
            var email = $("#email").val()
            res=$.ajax({url:"http://www.txy.com:9003/api/user/isRegistered?email="+email,async:false, type:'GET'});
            console.log("该邮箱是否已注册:"+res+","+res.responseText)
            if(res.responseText=="true") {
                $("#debug").html("<span style='color: red;'>该邮箱已注册!</span>")
                $("#debug").focus()
            }else {
                $("#debug").html("<span style='color: green;'>该邮箱可用</span>")
            }
        })

        $("#sendCodeBtn").click(function(){
            res=$.ajax({url:"http://www.txy.com:9003/api/user/"+$("#email").val()+"/sendCode",async:false, type:'POST'});
            console.log("邮件发送:"+res.responseText)
        });

        $("#registBtn").click(function () {
            res=$.ajax({url:"http://www.txy.com:9003/api/user/register?email="+$("#email").val()+"&password="+$("#password").val()+"&code="+$("#code").val(),async:false,type:'POST'});
            console.log("注册结果:"+res.responseText)
            if(res.responseText!="") {
                location.href = "main.html?token="+res.responseText
            }

        })
    });
</script>
</body>
</html>